import { describe, expect, it } from 'vitest';
import {
  numberToChinese,
  numToCn,
  numToCnReading,
} from '../../src/hammer/num.mts';

describe('numToCn', () => {
  it('should convert single digit numbers to chinese characters (small style)', () => {
    expect(numToCn(0)).toBe('零');
    expect(numToCn(1)).toBe('一');
    expect(numToCn(2)).toBe('二');
    expect(numToCn(3)).toBe('三');
    expect(numToCn(4)).toBe('四');
    expect(numToCn(5)).toBe('五');
    expect(numToCn(6)).toBe('六');
    expect(numToCn(7)).toBe('七');
    expect(numToCn(8)).toBe('八');
    expect(numToCn(9)).toBe('九');
  });

  it('should convert single digit numbers to chinese characters (big style)', () => {
    expect(numToCn(0, { big: true })).toBe('零');
    expect(numToCn(1, { big: true })).toBe('壹');
    expect(numToCn(2, { big: true })).toBe('贰');
    expect(numToCn(3, { big: true })).toBe('叁');
    expect(numToCn(4, { big: true })).toBe('肆');
    expect(numToCn(5, { big: true })).toBe('伍');
    expect(numToCn(6, { big: true })).toBe('陆');
    expect(numToCn(7, { big: true })).toBe('柒');
    expect(numToCn(8, { big: true })).toBe('捌');
    expect(numToCn(9, { big: true })).toBe('玖');
  });

  it('should convert multi-digit numbers to chinese characters (small style)', () => {
    expect(numToCn(10)).toBe('一零');
    expect(numToCn(23)).toBe('二三');
    expect(numToCn(456)).toBe('四五六');
    expect(numToCn(1234567890)).toBe('一二三四五六七八九零');
  });

  it('should convert multi-digit numbers to chinese characters (big style)', () => {
    expect(numToCn(10, { big: true })).toBe('壹零');
    expect(numToCn(23, { big: true })).toBe('贰叁');
    expect(numToCn(456, { big: true })).toBe('肆伍陆');
    expect(numToCn(1234567890, { big: true })).toBe('壹贰叁肆伍陆柒捌玖零');
  });

  it('should handle edge cases', () => {
    // Test default options
    expect(numToCn(5)).toBe('五');

    // Test with explicit default options
    expect(numToCn(5, { big: false })).toBe('五');

    // Test zero
    expect(numToCn(0)).toBe('零');
    expect(numToCn(0, { big: true })).toBe('零');
  });
});

describe('numberToChinese', () => {
  it('should convert basic numbers to chinese', () => {
    expect(numberToChinese(0)).toBe('零');
    expect(numberToChinese(1)).toBe('壹');
    expect(numberToChinese(2)).toBe('贰');
    expect(numberToChinese(5)).toBe('伍');
    expect(numberToChinese(10)).toBe('壹拾');
    expect(numberToChinese(11)).toBe('壹拾壹');
    expect(numberToChinese(15)).toBe('壹拾伍');
    expect(numberToChinese(19)).toBe('壹拾玖');
    expect(numberToChinese(20)).toBe('贰拾');
    expect(numberToChinese(23)).toBe('贰拾叁');
  });

  it('should convert numbers with hundreds', () => {
    expect(numberToChinese(100)).toBe('壹佰');
    expect(numberToChinese(101)).toBe('壹佰零壹');
    expect(numberToChinese(110)).toBe('壹佰壹拾');
    expect(numberToChinese(111)).toBe('壹佰壹拾壹');
    expect(numberToChinese(205)).toBe('贰佰零伍');
    expect(numberToChinese(567)).toBe('伍佰陆拾柒');
  });

  it('should convert numbers with thousands', () => {
    expect(numberToChinese(1000)).toBe('壹仟');
    expect(numberToChinese(1001)).toBe('壹仟零壹');
    expect(numberToChinese(1010)).toBe('壹仟零壹拾');
    expect(numberToChinese(1100)).toBe('壹仟壹佰');
    expect(numberToChinese(2005)).toBe('贰仟零伍');
    expect(numberToChinese(5678)).toBe('伍仟陆佰柒拾捌');
  });

  it('should convert numbers with ten thousands', () => {
    expect(numberToChinese(10000)).toBe('壹万');
    expect(numberToChinese(10001)).toBe('壹万零壹');
    expect(numberToChinese(50000)).toBe('伍万');
    expect(numberToChinese(50001)).toBe('伍万零壹');
    expect(numberToChinese(50010)).toBe('伍万零壹拾');
    expect(numberToChinese(50100)).toBe('伍万零壹佰');
    expect(numberToChinese(100000)).toBe('壹拾万');
    expect(numberToChinese(100001)).toBe('壹拾万零壹');
    expect(numberToChinese(100100)).toBe('壹拾万零壹佰');
    expect(numberToChinese(101000)).toBe('壹拾万壹仟');
    expect(numberToChinese(110000)).toBe('壹拾壹万');
  });

  it('should convert complex numbers', () => {
    expect(numberToChinese(123456789)).toBe(
      '壹亿贰仟叁佰肆拾伍万陆仟柒佰捌拾玖',
    );
    expect(numberToChinese(100000000)).toBe('壹亿');
    expect(numberToChinese(100000001)).toBe('壹亿零壹');
    expect(numberToChinese(100000010)).toBe('壹亿零壹拾');
    expect(numberToChinese(100000100)).toBe('壹亿零壹佰');
    expect(numberToChinese(100001000)).toBe('壹亿零壹仟');
    expect(numberToChinese(100010000)).toBe('壹亿零壹万');
    expect(numberToChinese(100100000)).toBe('壹亿零壹拾万');
    expect(numberToChinese(101000000)).toBe('壹亿零壹佰万');
    expect(numberToChinese(110000000)).toBe('壹亿壹仟万');
  });

  it('should handle edge cases', () => {
    // Test consecutive zeros
    expect(numberToChinese(10001)).toBe('壹万零壹');
    expect(numberToChinese(100001)).toBe('壹拾万零壹');
    expect(numberToChinese(1000001)).toBe('壹佰万零壹');

    // Test trailing zeros
    expect(numberToChinese(10000)).toBe('壹万');
    expect(numberToChinese(1000)).toBe('壹仟');
    expect(numberToChinese(100)).toBe('壹佰');
    expect(numberToChinese(10)).toBe('壹拾');
  });

  it('should handle very large numbers', () => {
    expect(numberToChinese(1000000000)).toBe('壹拾亿');
    expect(numberToChinese(10000000000)).toBe('壹佰亿');
    expect(numberToChinese(100000000000)).toBe('壹仟亿');
    expect(numberToChinese(1000000000000)).toBe('壹兆');
    expect(numberToChinese(10000000000000)).toBe('壹拾兆');
    expect(numberToChinese(100000000000000)).toBe('壹佰兆');
    expect(numberToChinese(1000000000000000)).toBe('壹仟兆');
  });

  it('should handle numbers with multiple zero patterns', () => {
    expect(numberToChinese(1001001)).toBe('壹佰万壹仟零壹');
    expect(numberToChinese(1010101)).toBe('壹佰零壹万零壹佰零壹');
    expect(numberToChinese(100010001)).toBe('壹亿零壹万零壹');
    expect(numberToChinese(1000000001)).toBe('壹拾亿零壹');
    expect(numberToChinese(1001001001)).toBe('壹拾亿零壹佰万壹仟零壹');
  });

  it('should handle numbers with all digits', () => {
    expect(numberToChinese(111111111)).toBe(
      '壹亿壹仟壹佰壹拾壹万壹仟壹佰壹拾壹',
    );
    expect(numberToChinese(222222222)).toBe(
      '贰亿贰仟贰佰贰拾贰万贰仟贰佰贰拾贰',
    );
    expect(numberToChinese(123456789012345)).toBe(
      '壹佰贰拾叁兆肆仟伍佰陆拾柒亿捌仟玖佰零壹万贰仟叁佰肆拾伍',
    );
  });

  it('should handle numbers starting with zero in groups', () => {
    expect(numberToChinese(100000000)).toBe('壹亿');
    expect(numberToChinese(10000000)).toBe('壹仟万');
    expect(numberToChinese(1000000)).toBe('壹佰万');
    expect(numberToChinese(100000)).toBe('壹拾万');
    expect(numberToChinese(10000)).toBe('壹万');
    expect(numberToChinese(1000)).toBe('壹仟');
    expect(numberToChinese(100)).toBe('壹佰');
    expect(numberToChinese(10)).toBe('壹拾');
  });

  it('should handle numbers with complex zero patterns', () => {
    expect(numberToChinese(1000000000000)).toBe('壹兆');
    expect(numberToChinese(1000000000001)).toBe('壹兆零壹');
    expect(numberToChinese(1000000000100)).toBe('壹兆零壹佰');
    expect(numberToChinese(1000000001000)).toBe('壹兆零壹仟');
    expect(numberToChinese(1000000010000)).toBe('壹兆零壹万');
    expect(numberToChinese(1000000100000)).toBe('壹兆零壹拾万');
    expect(numberToChinese(1000001000000)).toBe('壹兆零壹佰万');
    expect(numberToChinese(1000010000000)).toBe('壹兆零壹仟万');
    expect(numberToChinese(1000100000000)).toBe('壹兆零壹亿');
    expect(numberToChinese(1001000000000)).toBe('壹兆零壹拾亿');
  });

  it('should handle numbers near boundaries', () => {
    expect(numberToChinese(9999)).toBe('玖仟玖佰玖拾玖');
    expect(numberToChinese(99999)).toBe('玖万玖仟玖佰玖拾玖');
    expect(numberToChinese(999999)).toBe('玖拾玖万玖仟玖佰玖拾玖');
    expect(numberToChinese(9999999)).toBe('玖佰玖拾玖万玖仟玖佰玖拾玖');
    expect(numberToChinese(99999999)).toBe('玖仟玖佰玖拾玖万玖仟玖佰玖拾玖');
    expect(numberToChinese(999999999)).toBe(
      '玖亿玖仟玖佰玖拾玖万玖仟玖佰玖拾玖',
    );
    expect(numberToChinese(9999999999)).toBe(
      '玖拾玖亿玖仟玖佰玖拾玖万玖仟玖佰玖拾玖',
    );
  });

  it('should handle numbers with single digit in high positions', () => {
    expect(numberToChinese(200000000)).toBe('贰亿');
    expect(numberToChinese(3000000000)).toBe('叁拾亿');
    expect(numberToChinese(40000000000)).toBe('肆佰亿');
    expect(numberToChinese(500000000000)).toBe('伍仟亿');
    expect(numberToChinese(6000000000000)).toBe('陆兆');
    expect(numberToChinese(70000000000000)).toBe('柒拾兆');
    expect(numberToChinese(800000000000000)).toBe('捌佰兆');
    expect(numberToChinese(9000000000000000)).toBe('玖仟兆');
  });
});

describe('numToCnReading', () => {
  it('should convert basic numbers to chinese using zero-elimination method', () => {
    expect(numToCnReading(0)).toBe('零');
    expect(numToCnReading(1)).toBe('壹');
    expect(numToCnReading(2)).toBe('贰');
    expect(numToCnReading(5)).toBe('伍');
    expect(numToCnReading(10)).toBe('壹拾');
    expect(numToCnReading(11)).toBe('壹拾壹');
    expect(numToCnReading(15)).toBe('壹拾伍');
    expect(numToCnReading(19)).toBe('壹拾玖');
    expect(numToCnReading(20)).toBe('贰拾');
    expect(numToCnReading(23)).toBe('贰拾叁');
  });

  it('should convert numbers with hundreds using zero-elimination method', () => {
    expect(numToCnReading(100)).toBe('壹佰');
    expect(numToCnReading(101)).toBe('壹佰零壹');
    expect(numToCnReading(110)).toBe('壹佰壹拾');
    expect(numToCnReading(111)).toBe('壹佰壹拾壹');
    expect(numToCnReading(205)).toBe('贰佰零伍');
    expect(numToCnReading(567)).toBe('伍佰陆拾柒');
  });

  it('should convert numbers with thousands using zero-elimination method', () => {
    expect(numToCnReading(1000)).toBe('壹仟');
    expect(numToCnReading(1001)).toBe('壹仟零壹');
    expect(numToCnReading(1010)).toBe('壹仟零壹拾');
    expect(numToCnReading(1100)).toBe('壹仟壹佰');
    expect(numToCnReading(2005)).toBe('贰仟零伍');
    expect(numToCnReading(5678)).toBe('伍仟陆佰柒拾捌');
  });

  it('should convert numbers with ten thousands using zero-elimination method', () => {
    expect(numToCnReading(10000)).toBe('壹万');
    expect(numToCnReading(10001)).toBe('壹万零壹');
    expect(numToCnReading(50000)).toBe('伍万');
    expect(numToCnReading(50001)).toBe('伍万零壹');
    expect(numToCnReading(50010)).toBe('伍万零壹拾');
    expect(numToCnReading(50100)).toBe('伍万零壹佰');
    expect(numToCnReading(100000)).toBe('壹拾万');
    expect(numToCnReading(100001)).toBe('壹拾万零壹');
    expect(numToCnReading(100100)).toBe('壹拾万零壹佰');
    expect(numToCnReading(101000)).toBe('壹拾万壹仟');
    expect(numToCnReading(110000)).toBe('壹拾壹万');
  });

  it('should convert complex numbers using zero-elimination method', () => {
    expect(numToCnReading(123456789)).toBe(
      '壹亿贰仟叁佰肆拾伍万陆仟柒佰捌拾玖',
    );
    expect(numToCnReading(100000000)).toBe('壹亿');
    expect(numToCnReading(100000001)).toBe('壹亿零壹');
    expect(numToCnReading(100000010)).toBe('壹亿零壹拾');
    expect(numToCnReading(100000100)).toBe('壹亿零壹佰');
    expect(numToCnReading(100001000)).toBe('壹亿零壹仟');
    expect(numToCnReading(100010000)).toBe('壹亿零壹万');
    expect(numToCnReading(100100000)).toBe('壹亿零壹拾万');
    expect(numToCnReading(101000000)).toBe('壹亿零壹佰万');
    expect(numToCnReading(110000000)).toBe('壹亿壹仟万');
  });

  it('should handle zero patterns using zero-elimination method', () => {
    // 测试零合并
    expect(numToCnReading(10001)).toBe('壹万零壹');
    expect(numToCnReading(100001)).toBe('壹拾万零壹');
    expect(numToCnReading(1000001)).toBe('壹佰万零壹');
    expect(numToCnReading(1001001)).toBe('壹佰万壹仟零壹');
    expect(numToCnReading(1010101)).toBe('壹佰零壹万零壹佰零壹');
    expect(numToCnReading(100010001)).toBe('壹亿零壹万零壹');
    expect(numToCnReading(1000000001)).toBe('壹拾亿零壹');
  });

  it('should handle very large numbers using zero-elimination method', () => {
    expect(numToCnReading(1000000000)).toBe('壹拾亿');
    expect(numToCnReading(10000000000)).toBe('壹佰亿');
    expect(numToCnReading(100000000000)).toBe('壹仟亿');
    expect(numToCnReading(1000000000000)).toBe('壹兆');
    expect(numToCnReading(10000000000000)).toBe('壹拾兆');
    expect(numToCnReading(100000000000000)).toBe('壹佰兆');
    expect(numToCnReading(1000000000000000)).toBe('壹仟兆');
  });

  it('should handle edge cases using zero-elimination method', () => {
    // 测试边界情况
    expect(numToCnReading(0)).toBe('零');
    expect(numToCnReading(10)).toBe('壹拾');
    expect(numToCnReading(100)).toBe('壹佰');
    expect(numToCnReading(1000)).toBe('壹仟');
    expect(numToCnReading(10000)).toBe('壹万');
    expect(numToCnReading(100000000)).toBe('壹亿');

    // 测试连续零
    expect(numToCnReading(1000000000000)).toBe('壹兆');
    expect(numToCnReading(1000000000001)).toBe('壹兆零壹');
    expect(numToCnReading(1000000000100)).toBe('壹兆零壹佰');
    expect(numToCnReading(1000000001000)).toBe('壹兆零壹仟');
  });
});
